// components/navbar/index.js
const App = getApp();

Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  externalClasses: ['custom-class'],
  /**
   * 组件的属性列表
   */
  properties: {
    pageName:String,
    showNav: {
      type: Boolean,
      value: true
    },
    borderW:{ 
      type: String,
      value: '2rpx'
    },
    bgColor:{
      type: String,
      value: '#fff'
    },
    titleColor:{
      type: String,
      value: '#333'
    },
    iconColor:{
      type: String,
      value: '#000'
    },
    navIconList: {
      type: Array,
      value: [{
          iconName: 'zuojiantou',
          handleFun: '_navBack',
          bgColor: '#fff',
          iconColor: '#000'
        }
        // {
        //   iconName: 'index',
        //   handleFun: '_toIndex',
        //   bgColor: '#fff',
        //   iconColor: '#000'
        // }
      ]
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
  },
  lifetimes: {
    attached: function () {
      this.setData({
        navHeight: App.globalData.customNavInfo.navHeight,
        navTop: App.globalData.customNavInfo.navTop
      })
     }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //回退
    _navBack: function () {
      wx.navigateBack({
        delta: 1
      })      
    },
    //回主页
    _toIndex: function () {
      wx.switchTab({
        url: '/pages/home/home'
      })
    },
    //自定义icon回调
    iconCallback(e){
      this.triggerEvent(e.target.dataset.callback)
    }
  }
})
